#ifndef BLOCKQUEUE_H
#define BLOCKQUEUE_H
#include <QQueue>
#include <QMutex>
#include <QWaitCondition>
#include <QThread>
#include <QDateTime>
#include <QString>
struct LogMessage
{
    enum Level{
        Debug,
        Info,
        Warning,
        Error,
        Fatal
    };

    QString content;
    Level level;
    QDateTime timestamp;//时间戳
};

class BlockQueue
{
public:
    BlockQueue(int maxSize=1000);
    ~BlockQueue();

    //添加数据
    void enqueue(const LogMessage&msg);

    //移除数据
    LogMessage dequeue();

    //清理
    void clear();


    int size() const;


    void close();



private:
    QQueue<LogMessage> m_queue;
    mutable QMutex m_mutex;
    QWaitCondition m_notEmpty;
    QWaitCondition m_notFull;

     int m_maxSize;
    bool m_isClosed;

};

#endif // BLOCKQUEUE_H
